package cc.iotkit.manager.controller.adminMiniApp;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request;
import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo;
import cc.iotkit.manager.dto.vo.miniAdmin.*;
import cc.iotkit.manager.service.IDeviceDistributorService;
import cc.iotkit.model.device.DeviceInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"后台管理设备管理"})
@Slf4j
@RestController
@RequestMapping("/miniAdmin/device")
public class MiniAdminDeviceDistributorController {

    @Autowired
    private IDeviceDistributorService deviceDistributorService;

    @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "POST")
    @PostMapping("/list")
    public Paging<MiniAdminDeviceDistributorVo> getDevices(@RequestBody PageRequest<String> pageRequest) {
        return deviceDistributorService.getDevices(pageRequest);
    }

    @ApiOperation("获取设备详情")
    @PostMapping("/getDetail")
    public MiniAdminDeviceDistributorDetailVo getDetail(@RequestBody MiniAdminDeviceDetailVo detailVo) {
        return deviceDistributorService.getDetail(detailVo.getBindId());
    }

    @ApiOperation("新增设备")
    @PostMapping("/addDevice")
    public void registerDevice(@RequestBody MiniAdminDeviceDistributorVo deviceDistributorVo) {
         deviceDistributorService.registerDevice(deviceDistributorVo);
    }


    @ApiOperation("编辑设备")
    @PostMapping("/updateDevice")
    public void updateDevice(@RequestBody MiniAdminDeviceDistributorVo deviceDistributorVo) {
        deviceDistributorService.updateDevice(deviceDistributorVo);
    }

    @ApiOperation("解绑")
    @PostMapping("/unbindDevice")
    public void unbindDevice(@RequestBody Request<MiniAdminUnbindDeviceDistributorVo> deviceDistributorVo) {
        deviceDistributorService.unbindDevice(deviceDistributorVo.getData());
    }

    @ApiOperation("测试")
    @PostMapping("/test")
    public void test(@RequestBody MiniAdminDeviceTestVo deviceTestVoRequest) {
        deviceDistributorService.test(deviceTestVoRequest);
    }

    @ApiOperation("检测电流")
    @PostMapping("/testElectric")
    public void testElectric(@RequestBody Request<MiniAdminDeviceTestVo> deviceTestVoRequest) {
        deviceDistributorService.testElectric(deviceTestVoRequest.getData());
    }


    @ApiOperation("获取设备货道列表")
    @PostMapping("/getChannelList")
    public List<MiniAdminDeviceDistributorChannelVo>
    getChannelList(@RequestBody MiniAdminDeviceDetailVo detailVo) {
        return deviceDistributorService.getChannelList(detailVo.getBindId());
    }


    @ApiOperation("保存货道列表")
    @PostMapping("/saveChannelList")
    public void saveChannelList(@RequestBody List<MiniAdminDeviceDistributorChannelVo> channelVoList) {
         deviceDistributorService.saveChannelList(channelVoList);
    }


    @ApiOperation("保存货道列表")
    @PostMapping("/resetChannelList")
    public void resetChannelList(@RequestBody MiniAdminDeviceDetailVo detailVo) {
         deviceDistributorService.resetChannelList(detailVo.getBindId());
    }









}
